var MyTable={
    searchForm:"searchForm",
    searchUrl:"/role/list",
	tableId:"lgTable",
	table:null,
	prefix:"/role/"
};

$(function() {
    var defaultColunms = MyTable.initColumn();
    var table = new BSTable(MyTable.tableId, MyTable.searchUrl,defaultColunms);
	table.setQueryParams(getFormJson(MyTable.searchForm));
	table.setSingleSelect(true);
	table.setSortName("desc");
	table.setSortOrder("gmt_create");
	MyTable.table = table.init(0);
});
function reLoad() {
	MyTable.table.refresh(getFormJson(MyTable.searchForm));
}
function resetSearch(){
	cleanFormVal(MyTable.searchForm);
	MyTable.table.refresh(null);
}

MyTable.initColumn = function () {
    var columns =  [
		{checkbox : true},
		{field : 'roleId', title : '序号'},
		{field : 'roleName',title : '角色名称'},
		{field : 'roleSign',title : '角色标识'},
		{field : 'remark',title : '备注'},
		{
			title : '操作',
			field : 'id',
			align : 'center',
			formatter : function(value, row, index) {
				var e = '<a  class="btn btn-primary btn-sm ' + editBtn + '" href="#" mce_href="#" title="编辑" onclick="edit(\''
				+ row.roleId
				+ '\')"><i class="fa fa-edit "></i></a> ';
			var d = '<a class="btn btn-warning btn-sm ' + delBtn + '" href="#" title="删除"  mce_href="#" onclick="delRow(\''
				+ row.roleId
				+ '\')"><i class="fa fa-remove"></i></a> ';
			var f = '<a class="btn btn-warning btn-sm ' + assignBtn + '" href="#" title="分配菜单"  mce_href="#" onclick="assign(\''
			+ row.roleId
			+ '\')"><i class="fa fa-check"></i></a> ';
			return e + d+f;
			}
		} ];
    return columns;
};

function delRow(roleId){
    var config={
			url : MyTable.prefix+"/deleteRow",
			data:{"roleId":roleId},
			sureDo:true,
			msg:"确定删除记录？"
	}
	EasyAjax.post_json(config,function(r){
		layer.msg(r.msg);
		if (r.code == 0){
			reLoad();
		} 
	});
}
	
function add() {
	layer.open({
		type : 2,
		title : '创建角色',
		maxmin : true,
		shadeClose : false, // 点击遮罩关闭层
		area : [ '700px', '500px' ],
		content : MyTable.prefix + '/add/'
	});
}

function assign(roleId){
	layer.open({
		type : 2,
		title : '分配菜单',
		maxmin : true,
		shadeClose : false, // 点击遮罩关闭层
		area : [ '400px', '620px' ],
		content : MyTable.prefix+'roleMenu/assign/'+roleId
	});
	
}

function edit(roleId) {
	layer.open({
		type : 2,
		title : '修改角色',
		maxmin : true,
		shadeClose : false, // 点击遮罩关闭层
		area : [ '700px', '500px' ],
		content : MyTable.prefix+'/edit/'+roleId
	});
}
